﻿using System;
using Autodesk.Revit.DB;

namespace YJKRevitKernel.CurveUtility.ColinearCurveGroup
{
	internal class BaseLinePacker
	{
		internal Curve BaseLine
		{
			get
			{
				return this.m_BaseLine;
			}
			set
			{
				this.m_BaseLine = value;
			}
		}

		internal BaseLinePacker(Curve inputCurve)
		{
			this.GetBaseLineHashCode(inputCurve);
		}

		public override int GetHashCode()
		{
			return this.m_baseLineString.GetHashCode();
		}

		public override bool Equals(object obj)
		{
			if (!(obj is BaseLinePacker))
			{
				return base.Equals(obj);
			}
			return this.m_baseLineString.Equals((obj as BaseLinePacker).m_baseLineString);
		}

		private void GetBaseLineHashCode(Curve inputCurve)
		{
			this.BaseLine = inputCurve.Clone();
			this.BaseLine.MakeUnbound();
			XYZ xyzpoint = this.BaseLine.Project(this.m_referencePoint).XYZPoint;
			XYZ xyz = this.RoundPoint(this.GetForwardDirection(inputCurve), 6);
			this.m_baseLineString = xyzpoint.ToString() + xyz.ToString();
		}

		private XYZ GetForwardDirection(Curve m_useCurve)
		{
			Line line = m_useCurve as Line;
			return new XYZ(Math.Abs(line.Direction.Normalize().X), Math.Abs(line.Direction.Normalize().Y), Math.Abs(line.Direction.Normalize().Z));
		}

		private XYZ RoundPoint(XYZ inputPoint, int digits)
		{
			return new XYZ(Math.Round(inputPoint.X, digits), Math.Round(inputPoint.Y, digits), Math.Round(inputPoint.Z, digits));
		}

		private const int m_useDigits = 6;

		private XYZ m_referencePoint = XYZ.Zero;

		private string m_baseLineString;

		private Curve m_BaseLine;
	}
}
